package com.api.devices.domain.vo;

import com.api.common.utils.StringUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.ObjectUtils;

import java.util.Date;

@Setter
@Getter
public class SourceVo {
    private String monitoredCode;
    private String fileCode;
    private int access;
//    private String datCol;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date startTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date endTime;
    private String ipcCode;
    private String ip;
    private String user;
    private String password;
    public void setMonitoredCode(String monitoredCode) {
//        this.ipcCode = monitoredCode.contains("_")?monitoredCode.split("_")[0]:"";
        this.monitoredCode = monitoredCode;
        if(monitoredCode.length()>19 && StringUtils.isNotEmpty(monitoredCode)){
            this.ipcCode = monitoredCode.substring(0,7);
//        000_000_003_001_004_001
            this.access = Integer.parseInt(monitoredCode.substring(16,19));
            this.fileCode = monitoredCode.substring(0,15);
        }
    }

    public void setIpcCode(String ipcCode) {
        if(StringUtils.isNotEmpty(ipcCode)) {
            this.ipcCode = ipcCode;
        }
    }
}
